package com.gzk.user.controller;

import com.gzk.basic.exception.BusinessException;
import com.gzk.basic.util.AjaxResult;
import com.gzk.user.dto.LoginDto;
import com.gzk.user.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService loginService;

    @PostMapping("/account")
    public AjaxResult login(@RequestBody LoginDto dto){
        try {
            Map<String,Object> map = loginService.login(dto);
            return AjaxResult.ok().setResultObj(map);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.ok().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }


    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody Map<String,String> map){
        try {
            return loginService.wechat(map);

        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.ok().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！!！");
        }
    }
    @PostMapping("/binder/wechat")
    public AjaxResult binder(@RequestBody Map<String,String> map){
        try {
            Map<String, Object> binder = loginService.binder(map);
            return AjaxResult.ok().setResultObj(binder);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.ok().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }


}
